package cn.com.guanying.android.ui.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import cn.com.guanying.R;
import cn.com.guanying.android.GuanYingApplication;
import cn.com.guanying.javacore.v11.common.FLog;

public class ImageAdapter extends BaseAdapter{

	private ArrayList<Integer> mImages ;
	private LayoutInflater mInflater;
	public ImageAdapter(ArrayList<Integer> images){
		mImages = images;
		mInflater = (LayoutInflater) GuanYingApplication.getApplictionContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if(images==null){
			mImages = new ArrayList<Integer>();
		}
	}
	
	public int getCount() {
		return mImages.size();
	}

	public Object getItem(int position) {
		return mImages.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_image_list, null);
		}
		Gallery.LayoutParams localLayoutParams = new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		convertView.setLayoutParams(localLayoutParams);
		((ImageView) convertView.findViewById(R.id.imgView)).setBackgroundResource(mImages.get(position%mImages.size()));
		FLog.e("get Image index:"+position);
		return convertView;
	}

}
